﻿using FinModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FinTrade
{
    public class QuickTrade : ITrading
    {
        private List<Trade> _trades = new List<Trade>();

        public void Order(IEnumerable<Trade> trades, TradeContext context)
        {
            //post an trade
            //save an trade
            foreach (var trade in trades)
            {
                DeliverTrade(trade, context);
            }

            _trades.AddRange(trades);
        }

        private void DeliverTrade(Trade trade, TradeContext context)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("TRADE----{0,-20}{1,-30}{2,8}{3,10:0.00}{4,10:0.00}", trade.Instrument.Name, trade.TS, trade.Type, trade.Price, trade.Quantity);
            Console.ResetColor();
        }

        public IEnumerable<Trade> SearchTrades(DateTime from, DateTime to)
        {
            return _trades.Where(p => p.TS > from && p.TS <= to);
        }

        public void Cancel(IEnumerable<Trade> trades, TradeContext context)
        {
            foreach (var trade in trades) _trades.Remove(trade);
        }
    }
}
